<template>
    <div class="app-container">
        <div class="head">
            <img src="@/assets/img/Layout/position.png" />
            <p class="see-block">采购退货详情</p>
        </div>
        <div class="view-container">
            <el-row class="status-title">
                <template v-if="detailData.dataType !== '5'">
                    <el-col class="mr20 width100" v-if="detailData.status == '1'">
                        <el-button
                            class="btn-default width100"
                            type="primary"
                            @click="audit()"
                            v-hasPermi="['system:purchaseReturnOrder:approve']"
                        >审核</el-button>
                    </el-col>
                    <el-col class="mr20 width100" v-if="detailData.status == '2'">
                        <el-button
                            class="btn-audit width100"
                            type="primary"
                            @click="theAudit()"
                            v-hasPermi="['system:purchaseReturnOrder:approve']"
                        >反审核</el-button>
                    </el-col>
                    <el-col class="mr20 width100" v-if="detailData.status == '0'">
                        <el-button
                            class="btn-default width100"
                            type="primary"
                            @click="edit()"
                            v-hasPermi="['system:purchaseReturnOrder:edit']"
                        >编辑</el-button>
                    </el-col>
                </template>
                <el-col :span="10" class="status-container">
                    <div class="status-item">
                        <span :class="{ 'active' : detailData.approvalStatus == '0'}">待审核</span>
                        <span :class="{ 'active' : detailData.approvalStatus == '1'}">已审核</span>
                        <span :class="{ 'active' : detailData.approvalStatus == '2'}">反审核</span>
                        <span :class="{ 'active' : detailData.approvalStatus == '3'}">拒绝</span>
                    </div>
                </el-col>
            </el-row>
            <el-row class="detail-item">
                <el-col :span="8">
                    <span>采购退货编码：</span>{{ detailData.code ?  detailData.code : '暂无'}}
                </el-col>
                <el-col :span="9">
                    <span>业务日期：</span>{{ detailData.businessDate ?  detailData.businessDate : '暂无'}}
                </el-col>
            </el-row>
            <el-row class="detail-item">
                <el-col :span="8">
                    <span>供应商名称：</span>{{ detailData.supplierName ?  detailData.supplierName : '暂无'}}
                </el-col>
                <el-col :span="8">
                    <span>要求退货：</span>{{ detailData.arrivalDate ?  detailData.arrivalDate : '暂无'}}
                </el-col>
            </el-row>
            <el-row class="detail-item">
                <el-col :span="8">
                    <span>业务模式：</span>{{ detailData.businessModel == '0' ?  '采购退货' : '暂无'}}
                </el-col>
                <el-col :span="8">
                    <span>业务部门：</span>{{ detailData.businessUnit ?  detailData.businessUnit : '暂无'}}
                </el-col>
            </el-row>
            <el-row class="detail-item">
                <el-col :span="8">
                    <span>是否有源单：</span>{{ detailData.haveOrNot == '1' ? '是' : detailData.haveOrNot == '0' ? '否' : '暂无'}}
                </el-col>
                <el-col :span="8" v-if="detailData.haveOrNot == '1'">
                    <span>是否全退：</span>{{ detailData.allOrNot == '1' ? '是' : detailData.allOrNot == '0' ? '否' : '暂无' }}
                </el-col>
            </el-row>
            <el-row class="detail-item">
                <el-col :span="8" v-if="detailData.haveOrNot == '1'">
                    <span>源采购订单：</span>{{ detailData.purchaseOrderCode ? detailData.purchaseOrderCode : '暂无' }}
                </el-col>
                <el-col :span="8">
                    <span>发票类型：</span>{{ detailData.invoiceType == '1' ? '普通发票' : detailData.invoiceType == '2' ? '增值税发票' : '暂无' }}
                </el-col>
            </el-row>
            <el-row class="detail-item">
                <el-col :span="8">
                    <span>退货原因：</span>{{ detailData.reasonForReturn ? detailData.reasonForReturn : '暂无' }}
                </el-col>
                <el-col :span="8">
                    <span>备注：</span>{{ detailData.remark ? detailData.remark : '暂无' }}
                </el-col>
            </el-row>
            <el-row class="detail-item">
                <el-col :span="8">
                    <span>状态：</span>
                    <font v-if="detailData.approvalStatus == 0" style="color:#13C2C2">待审核</font>
                    <font v-if="detailData.approvalStatus == 1" style="color:#52C41A">已审核</font>
                    <font v-if="detailData.approvalStatus == 2" style="color:#fd562c">反审核</font>
                    <font v-if="detailData.approvalStatus == 3" style="color:#fd562c">拒绝</font>
                    <font v-if="detailData.approvalStatus == null" style="color:#13C2C2">草稿</font>
                </el-col>
            </el-row>
            <el-row class="detail-item">
                <el-col :span="24">
                    <el-table :data="detailData.purchaseReturnOrderDetailList" border>
                        <el-table-column label="序号" type="index" align="center" width="50" />
                        <el-table-column :label="item.label" :prop="item.prop" :width="item.width" v-for="(item, index) in columns" :key="index" align="center">
                        <template slot-scope="scope">
                            <!-- <template v-if="item.type == 'gift'">
                                {{ scope.row[item.prop] == '0' ? '否' : scope.row[item.prop] == '1' ? '是' : '' }}
                            </template> -->
                            <span>{{ scope.row[item.prop] }}</span>
                        </template>
                        </el-table-column>
                    </el-table>
                </el-col>
            </el-row>
            <el-row class="detail-item">
                <el-col :span="8">
                    <span>合计数量：</span>{{ detailData.totalNum ?  detailData.totalNum : '暂无'}}
                </el-col>
                <!-- <el-col :span="8">
                    <span>合计未税金额：</span>{{ detailData.totalAmount ?  detailData.totalAmount : '暂无'}}
                </el-col>
                <el-col :span="8">
                    <span>合计价税合计：</span>{{ detailData.totalTaxAmount ?  detailData.totalTaxAmount : '暂无'}}
                </el-col> -->
            </el-row>
            <el-row class="detail-item">
                <el-col :span="6">
                    <span>创建人：</span>{{ detailData.createBy ?  detailData.createBy : '暂无'}}
                </el-col>
                <el-col :span="6">
                    <span>创建日期：</span>{{ detailData.createTime ?  detailData.createTime : '暂无'}}
                </el-col>
                <el-col :span="6">
                    <span>审核人：</span>{{ detailData.approvalBy ?  detailData.approvalBy : '暂无'}}
                </el-col>
                <el-col :span="6">
                    <span>审核日期：</span>{{ detailData.approvalTime ?  detailData.approvalTime : '暂无'}}
                </el-col>
            </el-row>
        </div>
        <!-- 审核 -->
        <el-dialog :visible.sync="open" width="500" top="100px" append-to-body title="审核意见" center>
            <el-row>
                <el-col :span="24">
                    <textarea
                        class="approve-textarea"
                        v-model="approveRemark"
                        type="textarea"
                        placeholder="请输入意见和看法"
                    />
                </el-col>
            </el-row>
            <div slot="footer" class="dialog-footer">
                <el-button
                    type="primary"
                    class="btn-success mr20 width100"
                    @click="agreeApprove()"
                >同意</el-button>
                <el-button
                    type="primary"
                    class="btn-cancel width100"
                    @click="disagreeApprove()"
                >拒绝</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import { returnDetail, returnAudit } from "@/api/system/purchaseReturn/purchaseReturn"
export default {
    name: "detail",
    data() {
        return {
            id: '',
            detailData: '',
            // 表头
            columns: [{
                prop: "productBasicCode",
                label: "产品编码",
                width: 150,
            },{
                prop: "productBasicName",
                label: "产品名称",
                width: 150,
            },{
                prop: "specificationCode",
                label: "SKU编码",
                width: 150,
            },{
                prop: "specificationName",
                label: "SKU名称",
                width: 150,
            },{
                prop: "productShortName",
                label: "简称",
            },{
                prop: "specification",
                label: "规格",
            },
            // {
            //     prop: "batchNumber",
            //     label: "批次",
            //     width: 150,
            // },
            {
                prop: "picksNum",
                label: "可退数量",
                width: 100,
            },{
                prop: "planNum",
                label: "申退数量",
                width: 100,
            },{
                prop: "unit",
                label: "单位",
                width: 100,
            },
            // {
            //     prop: "untaxedAmount",
            //     label: "未税金额",
            //     width: 100,
            // },{
            //     prop: "taxRate",
            //     label: "税率",
            //     width: 100,
            // },{
            //     prop: "levy",
            //     label: "税款",
            //     width: 100,
            // },{
            //     prop: "totalTax",
            //     label: "价税合计",
            //     width: 100,
            // },{
            //     prop: "isGift",
            //     label: "赠品",
            //     width: 100,
            // },{
            //     prop: "arrivalDate",
            //     label: "到货日期",
            //     width: 215,
            // },{
            //     prop: "requisitionNumber",
            //     label: "关联申请单号",
            //     width: 100,
            // },{
            //     prop: "warehouseOut",
            //     label: "实退出库",
            //     width: 100,
            // },
            {
                prop: "remark",
                label: "备注",
                width: 100,
            }],
            open: false,
            approveRemark: ''
        }
    },
    created(){
        this.id = this.$route.query.id
        this.getDetailData()
    },
    methods: {
        // 获取详情数据
        getDetailData(){
            returnDetail(this.id).then(res => {
                this.detailData = res.data
            })
        },
        // 审核
        audit(){
            this.open = true
        },
        // 通过
        agreeApprove(){
            let data = this.detailData
            data.oldApprovalStatus = data.approvalStatus
            data.status = '2'
            data.approvalStatus = '1'
            returnAudit(this.detailData).then(res => {
                if(res.code == 200){
                    this.open = false
                    this.$modal.msgSuccess("操作成功")
                    this.$tab.closeOpenPage({ path: "/purchase/purchaseReturn/list" })
                }
            })
        },
        // 拒绝
        disagreeApprove(){
            let data = this.detailData
            data.oldApprovalStatus = data.approvalStatus
            data.status = '0'
            data.approvalStatus = '3'
            returnAudit(data).then(res => {
                if(res.code == 200){
                    this.open = false
                    this.$modal.msgSuccess("操作成功")
                    this.$tab.closeOpenPage({ path: "/purchase/purchaseReturn/list" })
                }
            })
        },
        // 反审核
        theAudit(){
            this.$modal.confirm('是否确认反审核？', '反审核').then(() => {
                let data = this.detailData
                data.oldApprovalStatus = data.approvalStatus
                data.status = '0'
                data.approvalStatus = '2'
                returnAudit(data).then(res => {
                    if(res.code == 200){
                        this.open = false
                        this.$modal.msgSuccess("操作成功")
                        this.$tab.closeOpenPage({ path: "/purchase/purchaseReturn/list" })
                    }
                })
            }).catch(() => {})
        },
        // 编辑
        edit(){
            this.$tab.closeOpenPage({ path: "/purchase/purchaseReturn/edit", query:{id: this.id} })
        }
    }
}
</script>
